home *** CD-ROM | disk | FTP | other *** search
/ Clickx 23 / Clickx 23.iso / DATA / moveabletype / MT-3.2-en_US / mt-check.cgi < prev    next >
Encoding:
Text File  |  2005-08-25  |  11.1 KB  |  351 lines

  1. #!/usr/bin/perl -w
  2.  
  3. # Copyright 2001-2005 Six Apart. This code cannot be redistributed without
  4. # permission from www.sixapart.com.  For more information, consult your
  5. # Movable Type license.
  6. #
  7. # $Id: mt-check.cgi.pre 16433 2005-08-19 19:29:09Z bchoate $
  8.  
  9. use strict;
  10. sub BEGIN {
  11.     my $dir;
  12.     require File::Spec;
  13.     if (!($dir = $ENV{MT_HOME})) {
  14.         if ($0 =~ m!(.*[/\\])!) {
  15.             $dir = $1;
  16.         } else {
  17.             $dir = './';
  18.         }
  19.         $ENV{MT_HOME} = $dir;
  20.     }
  21.     unshift @INC, File::Spec->catdir($dir, 'lib');
  22.     unshift @INC, File::Spec->catdir($dir, 'extlib');
  23. }
  24.  
  25. local $| = 1;
  26.  
  27. my $mt;
  28. eval {
  29.     require MT;
  30.     $mt = MT->new();
  31. };
  32.  
  33. use MT::L10N;
  34. my $LH = $mt ? $mt->language_handle : MT::L10N->get_handle('en_US');
  35.  
  36. sub trans_templ {
  37.     my($text) = @_;
  38.     return $mt->translate_templatized($text) if $mt;
  39.     $text =~ s!(<MT_TRANS(?:\s+((?:\w+)\s*=\s*(["'])(?:<[^>]+?>|[^\3]+?)+?\3))+?\s*/?>)!
  40.         my($msg, %args) = ($1);
  41.         #print $msg;
  42.         while ($msg =~ /\b(\w+)\s*=\s*(["'])((?:<[^>]+?>|[^\2])*?)\2/g) {  #"
  43.             $args{$1} = $3;
  44.         }
  45.         $args{params} = '' unless defined $args{params};
  46.         my @p = map MT::Util::decode_html($_),
  47.                 split /\s*%%\s*/, $args{params};
  48.         @p = ('') unless @p;
  49.         my $translation = translate($args{phrase}, @p);
  50.         $translation =~ s/([\\'])/\\$1/sg if $args{escape};
  51.         $translation;
  52.     !ge;
  53.     $text;
  54. }
  55.  
  56. sub translate {
  57.     return $mt->translate(@_) if $mt;
  58.     $LH->maketext(@_);
  59. }
  60.  
  61. my $charset = $LH->encoding;
  62. print "Content-Type: text/html; charset=$charset\n\n";
  63. print trans_templ(<<HTML);
  64.  
  65. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  66. <html xmlns="http://www.w3.org/1999/xhtml">
  67.  
  68. <head>
  69.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  70.     <meta http-equiv="content-language" content="en" />
  71.     
  72.     <title><MT_TRANS phrase="Movable Type System Check"> [mt-check.cgi]</title>
  73.     
  74.     <style type=\"text/css\">
  75.         <!--
  76.         
  77.             body {
  78.                 font-family : Trebuchet MS, Tahoma, Verdana, Arial, Helvetica, Sans Serif;
  79.                 font-size : smaller;
  80.                 padding-top : 0px;
  81.                 padding-left : 0px;
  82.                 margin : 0px;
  83.                 padding-bottom : 40px;
  84.                 width : 80%;
  85.                 border-right : 1px dotted #8faebe;
  86.             }
  87.             
  88.             h1 {
  89.                 background : #8faebe;
  90.                 font-size: large;
  91.                 color : white;
  92.                 padding : 10px;
  93.                 margin-top : 0px;
  94.                 margin-bottom : 20px;
  95.                 text-align : center;
  96.             }
  97.             
  98.             h2 {
  99.                 color: #fff;
  100.                 font-size: small;
  101.                 background : #8faebe;
  102.                 padding : 5px 10px 5px 10px;
  103.                 margin-top : 30px;
  104.                 margin-left : 40px;
  105.                 margin-right : 40px;
  106.             }
  107.             
  108.             h3 {
  109.                 color: #333;
  110.                 font-size: small;
  111.                 margin-left : 40px;
  112.                 margin-bottom : 0px;
  113.                 padding-left : 20px;
  114.             }
  115.     
  116.             p {
  117.                 padding-left : 20px;
  118.                 margin-left : 40px;
  119.                 margin-right : 60px;
  120.                 color : #666;
  121.             }
  122.             
  123.             ul {
  124.                 padding-left : 40px;
  125.                 margin-left : 40px;
  126.             }
  127.             
  128.             .info {
  129.                 margin-left : 60px;
  130.                 margin-right : 60px;
  131.                 padding : 20px;
  132.                 border : 1px solid #666;
  133.                 background : #eaf2ff;
  134.                 color : black;
  135.             }
  136.         
  137.             .alert {
  138.                 padding : 15px;
  139.                 border : 1px solid #666;
  140.                 background : #ff9;
  141.                 color : black;
  142.             }
  143.             
  144.  
  145.             .ready {
  146.                 color: #fff;
  147.                 background-color: #9C6;
  148.             }
  149.  
  150.             .bad {
  151.                 padding-top : 0px;
  152.                 margin-top : 4px;
  153.                 border-left : 1px solid red;
  154.                 padding-left : 10px;
  155.                 margin-left : 60px;
  156.             }
  157.             
  158.             .good {
  159.                 color: #93b06b;
  160.                 padding-top : 0px;
  161.                 margin-top : 0px;
  162.             }
  163.         
  164.         //-->
  165.     </style>
  166.  
  167. </head>
  168.  
  169. <body>
  170.  
  171. <h1><MT_TRANS phrase="Movable Type System Check"> [mt-check.cgi]</h1>
  172.  
  173. <p class="info"><MT_TRANS phrase="This page provides you with information on your system\'s configuration and determines whether you have all of the components you need to run Movable Type."></p>
  174.  
  175.  
  176. HTML
  177.  
  178.  
  179. my $is_good = 1;
  180.  
  181. my @REQ = (
  182.     [ 'CGI', 0, 1, translate('CGI is required for all Movable Type application functionality.') ],
  183.  
  184.     [ 'HTML::Template', 2, 1, translate('HTML::Template is required for all Movable Type application functionality.') ],
  185.  
  186.     [ 'Image::Size', 0, 1, translate('Image::Size is required for file uploads (to determine the size of uploaded images in many different formats).') ],
  187.  
  188.     [ 'File::Spec', 0.8, 1, translate('File::Spec is required for path manipulation across operating systems.') ],
  189.  
  190.     [ 'CGI::Cookie', 0, 1, translate('CGI::Cookie is required for cookie authentication.') ],
  191. );
  192.  
  193. my @DATA = (
  194.     [ 'DB_File', 0, 0, translate('DB_File is required if you want to use the Berkeley DB/DB_File backend.') ],
  195.  
  196.     [ 'DBI', 1.21, 0, translate('DBI is required if you want to use any of the SQL database drivers.') ],
  197.  
  198.     [ 'DBD::mysql', 0, 0, translate('DBI and DBD::mysql are required if you want to use the MySQL database backend.') ],
  199.  
  200.     [ 'DBD::Pg', 1.32, 0, translate('DBI and DBD::Pg are required if you want to use the PostgreSQL database backend.') ],
  201.  
  202.     [ 'DBD::SQLite', 0, 0, translate('DBI and DBD::SQLite are required if you want to use the SQLite database backend.') ],
  203. );
  204.  
  205. my @OPT = (
  206.     [ 'HTML::Entities', 0, 0, translate('HTML::Entities is needed to encode some characters, but this feature can be turned off using the NoHTMLEntities option in mt.cfg.') ],
  207.  
  208.     [ 'LWP::UserAgent', 0, 0, translate('LWP::UserAgent is optional; It is needed if you wish to use the TrackBack system, the weblogs.com ping, or the MT Recently Updated ping.') ],
  209.  
  210.     [ 'SOAP::Lite', 0.50, 0, translate('SOAP::Lite is optional; It is needed if you wish to use the MT XML-RPC server implementation.') ],
  211.  
  212.     [ 'File::Temp', 0, 0, translate('File::Temp is optional; It is needed if you would like to be able to overwrite existing files when you upload.') ],
  213.  
  214.     [ 'Image::Magick', 0, 0, translate('Image::Magick is optional; It is needed if you would like to be able to create thumbnails of uploaded images.') ],
  215.  
  216.     [ 'Storable', 0, 0, translate('Storable is optional; it is required by certain MT plugins available from third parties.')],
  217.  
  218.     [ 'Crypt::DSA', 0, 0, translate('Crypt::DSA is optional; if it is installed, comment registration sign-ins will be accelerated.')],
  219.  
  220.     [ 'MIME::Base64', 0, 0, translate('MIME::Base64 is required in order to enable comment registration.')],
  221.  
  222.     [ 'XML::Atom', 0, 0, translate('XML::Atom is required in order to use the Atom API.')],
  223. );
  224.  
  225. use Cwd;
  226. my $cwd = '';
  227. {
  228.     my($bad);
  229.     local $SIG{__WARN__} = sub { $bad++ };
  230.     eval { $cwd = Cwd::getcwd() };
  231.     if ($bad || $@) {
  232.         eval { $cwd = Cwd::cwd() };
  233.         if ($@ && $@ !~ /Insecure \$ENV{PATH}/) {
  234.             die $@;
  235.         }
  236.     }
  237. }
  238.  
  239. my $ver = $^V ? join('.', unpack 'C*', $^V) : $];
  240. my $server = $ENV{SERVER_SOFTWARE};
  241. my $inc_path = join "<br />\n", @INC;
  242. print trans_templ(<<INFO);
  243. <h2><MT_TRANS phrase="System Information:"></h2>
  244. <ul>
  245.     <li><strong><MT_TRANS phrase="Current working directory:"></strong> <code>$cwd</code></li>
  246.     <li><strong><MT_TRANS phrase="MT home directory:"></strong> <code>$ENV{MT_HOME}</code></li>
  247.     <li><strong><MT_TRANS phrase="Operating system:"></strong> $^O</li>
  248.     <li><strong><MT_TRANS phrase="Perl version:"></strong> <code>$ver</code></li>
  249.     <li><strong><MT_TRANS phrase="Perl include path:"></strong> <code>$inc_path</code></li>
  250. INFO
  251. if ($server) {
  252. print trans_templ(<<INFO);
  253.     <li><strong><MT_TRANS phrase="Web server:"></strong> <code>$server</code></li>
  254. INFO
  255. }
  256.  
  257. ## Try to create a new file in the current working directory. This
  258. ## isn't a perfect test for running under cgiwrap/suexec, but it
  259. ## is a pretty good test.
  260. my $TMP = "test$$.tmp";
  261. local *FH;
  262. if (open(FH, ">$TMP")) {
  263.     my $mode = (stat($TMP))[2] & 07777;
  264.     if (($mode & 07000) && !($mode & 07700)) {
  265.         print trans_templ("    <li><MT_TRANS phrase=\"(Probably) Running under cgiwrap or suexec\"></li>\n");
  266.     }
  267.     unlink($TMP);
  268. }
  269.  
  270. print "\n\n</ul>\n";
  271.  
  272. exit if $ENV{QUERY_STRING} && $ENV{QUERY_STRING} eq 'sys-check';
  273.  
  274. use Text::Wrap;
  275. $Text::Wrap::columns = 72;
  276.  
  277. for my $list (\@REQ, \@DATA, \@OPT) {
  278.     my $data = ($list == \@DATA);
  279.     my $req = ($list == \@REQ);
  280.     my $type;
  281.     if ($data) {
  282.         $type = translate("Data Storage");
  283.     } elsif ($req) {
  284.         $type = translate("Required");
  285.     } else {
  286.         $type = translate("Optional");
  287.     }
  288.     print trans_templ(qq{<h2><MT_TRANS phrase="Checking for [_1] Modules:" params="$type"></h2>\n\t<div>\n});
  289.     if (!$req && !$data) {
  290.         print trans_templ(<<MSG);
  291.         <p class="info"><MT_TRANS phrase="The following modules are <strong>optional</strong>. If your server does not have these modules installed, you only need to install them if you require the functionality that the module provides."></p>
  292.  
  293. MSG
  294.     }
  295.     if ($data) {
  296.         print trans_templ(<<MSG);
  297.         <p class="info"><MT_TRANS phrase="Some of the following modules are required by the various data storage options in Movable Type. In order run the system, your server needs to have either DB_File, or else DBI and at least one of the other modules installed."></p>
  298.  
  299. MSG
  300.     }
  301.     my $got_one_data = 0;
  302.     my $dbi_is_okay = 0;
  303.     for my $ref (@$list) {
  304.         my($mod, $ver, $req, $desc) = @$ref;
  305.         print "    <h3>$mod" .
  306.             ($ver ? " (version >= $ver)" : "") . "</h3>";
  307.         eval("use $mod" . ($ver ? " $ver;" : ";"));
  308.         if ($@) {
  309.             $is_good = 0 if $req;
  310.             my $msg = $ver ?
  311.                       trans_templ(qq{<p class="bad"><MT_TRANS phrase="Either your server does not have [_1] installed, the version that is installed is too old, or [_1] requires another module that is not installed." params="$mod"> }) :
  312.                       trans_templ(qq{<p class="bad"><MT_TRANS phrase="Your server does not have [_1] installed, or [_1] requires another module that is not installed." params="$mod"> });
  313.             $msg   .= $desc .
  314.                       trans_templ(qq{ <MT_TRANS phrase="Please consult the installation instructions for help in installing [_1]." params="$mod"></p>\n\n});
  315.             print wrap("        ", "        ", $msg), "\n\n";
  316.         } else {
  317.             if ($data) {
  318.                 $dbi_is_okay if $mod eq 'DBI';
  319.                 if ($mod eq 'DB_File') {
  320.                     $got_one_data = 1;
  321.                 } elsif ($mod ne 'DBI') {
  322.                     if ($mod eq 'DBD::mysql') {
  323.                         if ($DBD::mysql::VERSION == 3.0000) {
  324.                             print trans_templ(qq{<p class="bad"><MT_TRANS phrase="The DBD::mysql version you have installed is known to be incompatible with Movable Type. Please install the current release available from CPAN."></p>});
  325.                         }
  326.                     }
  327.                     $got_one_data = 1 if $dbi_is_okay;
  328.                 }
  329.             }
  330.             print trans_templ(qq{<p class="good"><MT_TRANS phrase="Your server has [_1] installed (version [_2])." params="$mod%%} . $mod->VERSION . qq{"></p>\n\n});
  331.         }
  332.     }
  333.     $is_good &= $got_one_data if $data;
  334.     print "\n\t</div>\n\n";
  335. }
  336.  
  337. if ($is_good) {
  338.     print trans_templ(<<HTML);
  339.     
  340.     <h2 class="ready"><MT_TRANS phrase="Movable Type System Check Successful"></h2>
  341.  
  342.     <p><strong><MT_TRANS phrase="You're ready to go!"></strong> <MT_TRANS phrase="Your server has all of the required modules installed; you do not need to perform any additional module installations. Continue with the installation instructions."></p>
  343.  
  344. </div>
  345.  
  346.  
  347. HTML
  348. }
  349.  
  350. print "</body>\n\n</html>\n";
  351.